package logic

import (
	"context"
	"zhaowei/models/mysql"

	"zhaowei/baidurpc/baidurpc"
	"zhaowei/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentListLogic {
	return &CommentListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentListLogic) CommentList(in *baidurpc.CommentListRequest) (*baidurpc.CommentListResponse, error) {
	// todo: add your logic here and delete this line
	var a []mysql.Comment
	mysql.DB.Debug().Find(&a)

	var b []*baidurpc.CommentList
	for _, c := range a {
		list := baidurpc.CommentList{
			UserId: int64(c.UserId),
			Pl:     c.Pl,
			PostId: int64(c.PostId),
			Id:     int64(c.ID),
		}
		b = append(b, &list)
	}
	return &baidurpc.CommentListResponse{
		List: b,
	}, nil
}
